package com.xiyu.service.controller.admin.material;
import com.xiyu.service.vo.material.supplier.SupplierSimpleListOutput;
import com.xiyu.service.vo.material.supplier.SupplierSingleGetOutput;
import com.xiyu.service.vo.material.supplier.SupplierUpdateInput;
import com.xiyu.service.vo.material.supplier.SupplierCreateInput;
import com.xiyu.service.vo.material.supplier.SupplierPageQueryOutput;
import com.xiyu.service.vo.material.supplier.SupplierPageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.material.SupplierService;

@Tag(name = "供应商管理")
@RestController
@RequestMapping("/material/supplier")
@Validated
public class SupplierController {

    @Resource
    private SupplierService supplierService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询供应商")
    @PreAuthorize("@ss.hasPermission('material:supplier:query')")
    public CommonResult<PageResult<SupplierPageQueryOutput>> pageQuery(@Valid SupplierPageQueryInput inputVO) {
        return success(supplierService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增供应商")
    @PreAuthorize("@ss.hasPermission('material:supplier:create')")
    public CommonResult<Long> create(@Valid @RequestBody SupplierCreateInput inputVO) {
        return success(supplierService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新供应商")
    @PreAuthorize("@ss.hasPermission('material:supplier:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody SupplierUpdateInput inputVO) {
        return success(supplierService.update(inputVO));
    }

    @DeleteMapping("/deleted")
    @Operation(summary = "删除供应商")
    @PreAuthorize("@ss.hasPermission('material:supplier:delete')")
    @Parameter(name = "id", description = "供应商主键ID", example = "")
    public CommonResult<Boolean> deleted(@RequestParam("id") Long id) {
        return success(supplierService.deleted(id));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个供应商")
    @Parameter(name = "id", description = "供应商主键ID", example = "")
    public CommonResult<SupplierSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(supplierService.singleGet(id));
    }

    @GetMapping("/simple-list")
    @Operation(summary = "查询供应商精简信息")
    public CommonResult<List<SupplierSimpleListOutput>> simpleList() {
        return success(supplierService.simpleList());
    }

}
